
from math import sqrt
"""Class that defines vector operations."""
class vector:
	"""a vector class"""
	def __init__(self, x,y,z=0, info=None):
		self.x = float(x)
		self.y = float(y)
		self.z = float(z)
		self.info = info			# here we can store additional information
		self.r = self.abs()
		self.null = self.is_null()

	def is_null(self):
		return not ((self.x != 0.) or (self.y != 0.) or (self.z != 0.));

	def abs(self):
		"absolute value"
		return sqrt(self.x**2 + self.y**2  + self.z**2)

	def cross(self, other):
		"cross product"

		cx = self.y * other.z - self.z * other.y
		cy = self.z * other.x - self.x * other.z
		cz = self.x * other.y - self.y * other.x

		return vector(cx,cy,cz)

	def dot(self, other):
		"dot product"
		return self.x * other.x + self.y * other.y +self.z * other.z

	def norm(self):
		"Return a normalized vector"
		self.r = self.abs()
		if self.null: return self
		else:
			return vector(self.x/ self.r, self.y/self.r, self.z/self.r)

	def normalize(self):
		"Return a normalized vector"
		self.r = self.abs()

		if self.r != 0.:
			self /= self.r

	def __iadd__(self, other):
		" += "
		self.x += other.x
		self.y += other.y
		self.z += other.z

	def __isub__(self, other):
		" -= "

		self.x -= other.x
		self.y -= other.y
		self.z -= other.z

	def __imul__(self, val):
		"scalar *= multiplication"
		self.x *= val
		self.y *= val
		self.z *= val

	def __idiv__(self, val):
		"scalar /= division"
		self.x /= val
		self.y /= val
		self.z /= val

	def __add__(self, other):
		"addition of two vectors"
		return vector(self.x + other.x, self.y + other.y,self.z + other.z)

	def __sub__(self, other):
		"subtraction of two vectors"
		return vector(self.x - other.x, self.y - other.y,self.z - other.z)

	def __mul__(self, val):
		"scalar multiplication"
		return vector(self.x *val, self.y *val,self.z *val)

	def __div__(self, val):
		"scalar division"
		return self.__mul__(1./val)

	def prnt(self):
		"Print the values"
		print '[%f\t,\t%f\t,\t%f]' % (self.x, self.y, self.z)

	def __cmp__(self, other):
		"comparison of two vectors (lexicographically)"
		if cmp(self.x,other.x) != 0:
			return cmp(self.x,other.x)

		if cmp(self.y,other.y) != 0:
			return cmp(self.y,other.y)

		if cmp(self.z,other.z) != 0:
			return cmp(self.z,other.z)

		# only if both vectors are equal
		return 0

	def __hash__(self):
		return 0
